package com.pinyougou.sellergoods.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.pinyougou.mapper.TbSellerMapper;
import com.pinyougou.pojo.TbSeller;
import com.pinyougou.pojo.TbSellerExample;
import com.pinyougou.sellergoods.service.SellerService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class SellerServiceImpl implements SellerService {
    @Autowired
    private TbSellerMapper sellerMapper;
    @Override
    public PageInfo<TbSeller> findAll(TbSeller seller, Integer page, Integer size) {
        PageHelper.startPage(page,size);
        TbSellerExample sellerExample = new TbSellerExample();
        if (seller != null) {
            //名字模糊搜索
            if (seller.getName() != null && seller.getName().length() > 0 && seller.getName().trim().length() > 0) {
                sellerExample.createCriteria().andNameLike(seller.getName());
            }
            if (seller.getNickName() != null && seller.getNickName().length() > 0 && seller.getNickName().trim().length() > 0) {
                sellerExample.createCriteria().andNickNameLike(seller.getName());
            }
        }
        List<TbSeller> tbSellers = sellerMapper.selectByExample(sellerExample);
        return new PageInfo<>(tbSellers);
    }

    @Override
    public TbSeller getOneById(String id) {
        TbSeller tbSeller = sellerMapper.selectByPrimaryKey(id);
        return tbSeller;
    }

    @Override
    public void updateStatus(String sId, String status) {
        TbSeller tbSeller = sellerMapper.selectByPrimaryKey(sId);
        tbSeller.setStatus(status);
        sellerMapper.updateByPrimaryKey(tbSeller);
    }
}
